/*
 * Copyright (C) 2015-2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include "PlanetWars2dRT-core/specific/model/planets.h"
#include "PlanetWars2dRT-core/specific/model/planet_position.h"


EXTERN_C_BEGIN


position_2d_uint
planets_get_center_position(const planet_t* planets, size_t nb)
{
  position_2d_uint position_center;
  if(planets == NULL || nb == 0)
    {
      position_center.x = 0;
      position_center.y = 0;
      return position_center;
    }
  
  position_center.x = planet_get_center_position_x(&planets[0]);
  position_center.y = planet_get_center_position_y(&planets[0]);
  for(size_t i=1; i < nb; ++i)
    {
      position_center.x += planet_get_center_position_x(&planets[i]);
      position_center.y += planet_get_center_position_y(&planets[i]);
    }
  position_center.x /= nb;
  position_center.y /= nb;
  return position_center;
}

position_2d_uint
planets_ptr_get_center_position(const planet_t** planets, size_t nb)
{
  position_2d_uint position_center;
  if(planets == NULL || nb == 0)
    {
      position_center.x = 0;
      position_center.y = 0;
      return position_center;
    }
  
  position_center.x = planet_get_center_position_x(planets[0]);
  position_center.y = planet_get_center_position_y(planets[0]);
  for(size_t i=1; i < nb; ++i)
    {
      position_center.x += planet_get_center_position_x(planets[i]);
      position_center.y += planet_get_center_position_y(planets[i]);
    }
  position_center.x /= nb;
  position_center.y /= nb;
  return position_center;
}


EXTERN_C_END
